<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script charset="utf-8" src="scripts/vendor/kindeditor/kindeditor-min.js"></script>
<script charset="utf-8" src="ui/bootstrap/js/bootstrap-alert.js"></script>
<script charset="utf-8" src="scripts/vendor/kindeditor/lang/zh_CN.js"></script>
<script charset="utf-8" src="scripts/vendor/jquery.form.js"></script>
<script>
var editor;
KindEditor.ready(function(K) {
        editor = K.create('#ttContent', {
        	uploadJson : 'file/file-upload.action',
        	fileManagerJson : 'file/file-manager.action',
        	allowFileManager : true
        });
});
function save(status){
	$('#ttStatus').attr("value", status);
	if( editor.isEmpty() ){
		if(0 == $('#emptyAlert').length){
			$('#draft').after(warn());
		}
	}else{
		editor.sync();
		$('#comFill').trigger('submit');
	}
}

function warn(){
	return '<div id="emptyAlert" class="alert" style="width:200px;float:none;"><a class="close" data-dismiss="alert">×</a>'
			+' <strong>Warning!</strong> 内容不能为空</div>';
}

$(function(){
	$('#comFill').submit(function(){
		$('#comFill').ajaxSubmit(function(json){
			if(json.success){
				$('#ttid').val(json.timeTable.id);
				$('#ttversion').val(json.timeTable.version);
				$('#msg').show();
				$('#msg').fadeOut(5000);
			}else{
				alert("提交失败哦");
			}
		});
		return false;
	});
	
	$('#homework').click(function(){
		save('<s:property value="@org.projects.graduates.domain.ContentStatus@ARTWORK"/>');
		window.location = "course/homework-assignment.action?tid=<s:property value='timeTableId'/>";
	});
});

</script>
<title>填写课程内容</title>
</head>
<body>
	
	<div class="clearfix" style="font-size:150%;">
	<a href="course/teachings.action?tId=<s:property value='timeTable.course.id'/>"><s:property value='timeTable.course.name'/></a> 在   <s:date name="timeTable.teachDate" format="yyyy-MM-dd" />所授的内容
	<hr/>
	</div>
	
	<!-- 课程内容 -->
	<div>
	<form id="comFill" method="post" action="course/commit-fill-in.action">
		标题 &nbsp;&nbsp;<s:textfield name="timeTable.content.title" cssClass="span5"  />
		<div class="pull-right">
		<a href="course/teachings.action?tId=<s:property value='timeTable.course.id'/>">&lt;返回查看其他时间课程</a>&nbsp;或者&nbsp;
		<a id="homework" href="javascript:void(0);" class="btn">布置作业&gt;</a></div>
		<p>  
		<textarea id="ttContent" name="timeTable.content.txt" style="width:100%;height:300px;"><s:property value='timeTable.content.txt'/></textarea>   
		<input id="ttStatus" name="timeTable.status" type="hidden" value="<s:property value='timeTable.status'/>"/>
		<s:hidden id="ttid" name="timeTable.id"/>
		<s:hidden id="ttversion"  name="timeTable.version"/>
		<s:hidden name="timeTable.teachDate"/>
		<s:hidden name="timeTable.course.id"/>
		<s:hidden name="timeTable.course.version"/>
		</p>
	</form>
	</div>
	
	<div>
		<input id="artWork" class="btn" onclick="save('<s:property value="@org.projects.graduates.domain.ContentStatus@ARTWORK"/>')" type="button" value="提交" />
		<a id="draft" href="javascript:void(0);" onclick="save('<s:property value="@org.projects.graduates.domain.ContentStatus@DRAFT"/>')"  >草稿</a>
		<span id="msg" class="hide">保存成功</span>
	</div>
	
</body>
</html>